layui.use(['table', 'form', 'jquery', 'common', 'laydate'], function() {
			let table = layui.table;
			let form = layui.form;
			let $ = layui.jquery;
			let common = layui.common;
			let laydate = layui.laydate;

			let cols = [
				[{
					field: "id",
					title: "ID",
					unresize: "true",
					align: "center"
				}, {
					field: 'wx_user',
					title: '微信店员账号',
					width: 200,
					align: 'center',
				}, {
					field: "wx_name",
					title: "微信店员名称",
					unresize: "true",
					align: "center"
				}, {
					field: "status",
					title: "状态",
					unresize: "true",
					align: "center",
					templet: "#status"
				}, {
					field: "beizhu",
					title: "备注",
					unresize: "true",
					align: "center"
				}, {
					field: "addtime",
					title: "添加时间",
					unresize: "true",
					align: "center"
				}, {
					field: "active",
					title: "在线状态",
					unresize: "true",
					align: "center",
					templet: function (d){
					    return d.active;
					}
				}, {
					title: '操作',
					toolbar: '#options',
					unresize: true,
					align: 'center',
					width: 180,
				}]
			]

			table.render({
				elem: '#news',
				id: 'news',
				url: './ajax1.php?act=Wechat_TrumpetgetDataList',
				page: true,
				cols: cols,
				cellMinWidth: 100,
				skin: 'line',
				toolbar: '#toolbar',
				defaultToolbar: [{
					title: '刷新',
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports']
			});

			table.on('tool(news)', function(obj) {
				if (obj.event === 'remove') {
					window.remove(obj);
				} else if (obj.event === 'edit') {
					window.edit(obj);
				}
			});

			table.on('toolbar(news)', function(obj) {
				if (obj.event === 'add') {
					window.add();
				} else if (obj.event === 'refresh') {
					window.refresh();
				} else if(obj.event === 'force_bind'){
				    window.force_bind();
				}
			});

			// 修改状态
			form.on("switch(status)", function(data) {
				var id = this.value;
				var load = layer.load();
				$.post("./ajax.php", {
				    act:"Wechat_Trumpetstatus",
					id: id
				}, function(res) {
					layer.close(load);
					if (res.code == 200) {
						layer.msg(res.msg, {
							icon: 1,
							time: 1500
						})
					} else {
						layer.msg(res.msg, {
							icon: 2,
							time: 1500
						}, function() {
							$(data.elem).prop("checked", !$(data.elem).prop("checked"));
							form.render()
						})
					}
				}, "json")
			});
			//弹出窗设置 自己设置弹出百分比
			function screen() {
				if (typeof width !== 'number' || width === 0) {
					width = $(window).width() * 0.8;
				}
				if (typeof height !== 'number' || height === 0) {
					height = $(window).height() * 0.5;
				}
				return [width + 'px', height + 'px'];
			}

			
            $("#txtoken").click(function() {
				layer.open({
					type: 2,
					maxmin: true,
					title: '店员通讯token',
					shade: 0.1,
					area: screen(),
					content: "./Wechat_Trumpet?my=tc"
				});
			});
			
			// 添加数据
			window.add = function() {
				layer.open({
					type: 2,
					maxmin: true,
					title: '新增管理',
					shade: 0.1,
					area: screen(),
					content: "./Wechat_Trumpet?my=add"
				});
			}
			
			// 发送数据内容
			$("#addUser").click(function() { //添加微信
				var mode = $("#mode").val();
				var wx_user = $("#wx_user").val();
				var wx_name = $("#wx_name").val();
				var beizhu = $("#beizhu").val();
				var sort = $("#sort").val();
				var ii = layer.load(3, {
					shade: [0.1, '#fff']
				});
				$.ajax({
					type: "POST",
					url: "./ajax1.php?act=Add_Wechet_Tp",
					data: {
						mode,
						wx_user,
						wx_name,
						beizhu,
						sort
					},
					dataType: 'json',
					timeout: 10000,
					success: function(data) {
						layer.close(ii);
						if (data.code == 200) {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							}, function() {
								parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
								parent.layui.table.reload("news");
							});
						}else{
						    layer.msg(data.msg, {
								icon: 2,
								time: 1000
							});
						}
					},
					error: function(data) {
						layer.close(ii);
						layer.msg('服务器错误');
					}
				});

			});
			
			window.force_bind = function(obj){
			    layer.open({
					type: 2,
					maxmin: true,
					title: '强制绑定店员',
					shade: 0.1,
					area: screen(),
					content: './Wechat_Trumpet?my=force_bind'
				});
			}
			$("#addforce_bind").click(function() {
			    	var wx_username = $("#wx_username").val();
				    var wx_dyname = $("#wx_dyname").val();
				    var ii = layer.load(3, {
    					shade: [0.1, '#fff']
    				});
				    $.ajax({
					type: "POST",
					url: "./ajax.php",
					data: {
					    act:"wxpay_zt_Out",
						wx_username,
						wx_dyname
					},
					dataType: 'json',
					timeout: 10000,
					success: function(data) {
						layer.close(ii);
						if (data.code == 200) {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							}, function() {
								parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
								parent.layui.table.reload("news");
							});
						}else{
						    layer.msg(data.msg, {
								icon: 2,
								time: 1000
							});
						}
					},
					error: function(data) {
						layer.close(ii);
						layer.msg('服务器错误');
					}
				});
			});
			
			
				// 修改数据
			window.edit = function(obj) {
				layer.open({
					type: 2,
					maxmin: true,
					title: '修改管理',
					shade: 0.1,
					area: screen(),
					content: './Wechat_Trumpet?my=edit&id=' + obj.data['id']
				});
			}

			// 发送数据内容
			$("#editUser").click(function() { //修改微信
				var id = $("#id").val();
				var wx_user = $("#wx_user").val();
				var wx_name = $("#wx_name").val();
				var beizhu = $("#beizhu").val();
				var sort = $("#sort").val();
				var status = $("#status").val();
				if (wx_user == '' || wx_name == '') {
					layer.alert('必填项不能为空！');
					return false;
				}
				var ii = layer.load(3, {
					shade: [0.1, '#fff']
				});
				$.ajax({
					type: "POST",
					url: "./ajax1.php?act=Edit_Wechet_Tp",
					data: {
						id,
						wx_user,
						wx_name,
						beizhu,
						sort,
						status
					},
					dataType: 'json',
					timeout: 10000,
					success: function(data) {
						layer.close(ii);
						if (data.code == 200) {
							layer.msg(data.msg, {
								icon: 1,
								time: 1000
							}, function() {
								parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
								parent.layui.table.reload("news");
							});
						}else{
						    layer.msg(data.msg, {
								icon: 2,
								time: 1000
							});
						}
					},
					error: function(data) {
						layer.close(ii);
						layer.msg('服务器错误');
					}
				});
			});
			// 数据删除
			window.remove = function(obj) {
				layer.confirm('确定要删除该数据？', {
					icon: 3,
					title: '提示'
				}, function(index) {
					layer.close(index);
					let loading = layer.load();
					$.ajax({
						url: './ajax.php',
						data: {
						    act:"Wechat_Trumpetremove",
							id: obj.data['id']
						},
						dataType: 'json',
						type: 'POST',
						success: function(res) {
							layer.close(loading);
							if (res.code == 200) {
								layer.msg(res.msg, {
									icon: 1,
									time: 1000
								}, function() {
									obj.del();
								});
							} else {
								layer.msg(res.msg, {
									icon: 2,
									time: 1000
								});
							}
						}
					})
				});
			}

			window.refresh = function(param) {
				table.reload('news');
			}
		})